home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
utilitys
/
351
/
mandle
/
mandle.doc
next >
Wrap
Text File
|
1988-12-10
|
7KB
|
140 lines
Everyone owning a computer with any kind of graphics
capability should be able to enjoy the spectacular regions of
chaos surrounding the famous Mandelbrot Set. With 16 colours, 320
by 200 resolution and the powerful 68000 processor, the Atrari
STs can provide wonderful examples.
For those among you who have not heard of this mathematical
wonderland before, the Mandelbrot Set is a region surrounding the
origin of the complex plane. What complex numbers are is not
important. All that you need to know is that calculations
involving a pair of x,y coordinates are repeated several times
until either a set limit to the number of repetitions is reached
or a simple condition is met (see Procedure Calc in the program
listing for details). The number of repetitions needed is used to
determine the colour of the pixel at this position.
To fill a complete screen this procedure must be executed
320*200=64000 times. Remember that each time the procedure is
called there is the possibility that the total number of
repetitions may reach the limit selected (up to 500). Each of
these repetitions contains several real number arithmetic
operations. Even on an 8 MHz Atari this is a formidable amount of
processing.
Up until now the time taken to complete a drawing has been
the main drawback of all published programs which may be used to
draw the set and its neighbourhood (the actual Mandelbrot set is
the region, conventionally coloured black, in which the
repetitions reach the limit imposed without ever satisfying the
condition). It could take the patience of a saint, not to mention
a computer, to wait for four hours or more when drawing an
intricate area near the central set. (and this would be in
machine code!)
This program presents a powerful algorithm which decreases
the time taken in these calculations by between a half to a
quarter of that taken by the standard method!
The program was written in GFA Basic, chosen for both it`s
speed when interpreted and because it may be compiled to stand-
alone machine code which runs almost as fast as could be achieved
with direct assembler.
To achieve such a speed increase over conventional methods
it is necessary to eliminate many of the calls to the iterative
procedure, Procedure Calc. The picture is drawn a row of pixels
at a time with Calc called only every second pixel. The
intermediate pixels are only referred to Calc if the pixels on
either side are assigned different colours. An array, P%(2,320),
is used to store the colours during this process. A further
saving is made by calculating alternate rows in this way and then
filling in the intermediate rows, only calling Calc when the
pixels above and below the current pixel are different.
The program itself is driven by GEM menus and provides
facilities to save and load drawings; the ability to create new
drawings, both by typing parameters (bottom right x,y coord-
inates of the area, height of the area and limit on number of
repetitions) and by zooming in to an area of an existing picture
display; screen dumps on Epson compatible printers and three
types of colour cycling, providing stunning special effects.
The code is liberally commented and it should be relatively
easy to adapt the main procedures to other dialects of Basic or
different languages.
One feature of the code worth mentioning is the need to set
up the colour pallette carefully since GEM's colour numbers are
incompatible with the Atari's: see Procedure Pallette.
To run the program the Atari must be in low resolution mode.
Simply double-click on MANDEL.PRG, the compiled GFA code, and a
menu bar will appear. Lets draw your first picture!
Select "Options" from the menu bar and click on "New
Picture". This prompts a request for the four necessary parameters
to which you should respond as follows:
Real (x) coordinate of bottom left = -3
Imaginary (y) part = -2
Height of scan = 4
Maximum number of iterations (repetitions) = 40
These values are the ones needed to give you a bird's eye
view of the entire area of interest around the Mandelbrot Set.
This is a simple region to draw, even without using the
special algorithm to cut down the number of calculations needed.
Times for the completion of a drawing of this region are given
below (N.B. to place all pixels on the screen using the Plot
command takes roughly 1 minute even without any calculations!):
1) Interpreted Basic, all pixels calculated 11.3 min.
2) Interpreted Basic, special algorithm 6 min.
3) Compiled Basic, special algorithm 2.5 min.
Part of the fun, given reasonable drawing times, is the
exploration of the region using the "Zoom" option.
A box appears which may be moved around the screen and
varied in area using the left mouse button (smaller) or right
mouse button (larger). Once an area to be magnified has been
selected a press of the Space Bar will set the size parameters
and request an iteration limit.
Drawing may be terminated by holding down both mouse buttons
at the end of a two row drawing cycle.
This method is also used to end a special effects sequence.
While in such a sequence, the colour cycling may be speeded up
(left button) or slowed down (right button). N.B. the colours
used in FX1 and FX2 are selected randomly whenever called.
To help get you started here are the parameters needed to
draw 7 of the infinite number of areas worth examining:
-0.6397597794 0.49651713442 0.00036595175879 85
-0.17654926992 1.0226819053 0.020270540348 200
-0.7647 0.09134478 0.000337254 250
-0.74716042634 0.092600591738 0.0003656176938 200
-0.74742219026 0.092574071593 0.00002594815003 250
0.26745017517 0.0036936648457 0.0006335768162 200
0.2678361353 0.0038701979279 0.00011288901834 500
This last is a real test of the algorithm - not only does
the drawing of this region involve up to 500 iterations (probably
the upper limit because of arithmetic rounding errors affecting
accuracy) but also the region in question has an extremely
complex structure with rapidly changing colours. In compiled GFA
Basic the region is drawn in 2 hr 46 min. 250 iterations is the
greatest number you will normally need and you may expect to
complete such a drawing in around 1 hour (compiled Basic).
The GFA Basic source code, MANDEL.LST, is provided for the
benefit of those who wish to examine the algorithm (which may be
used to shorten execution times of other, similar programs). The
listing is given in ASCII format so that non-GFA Basic users may
dump it.
I hope you find the Mandelbrot set as fascinating and as
beautiful as I do. Many other effects are possible, feel free to
add your own. Happy drawing!